package com.better.backend.mqReceiverService.examReceiver.listener;

import com.alibaba.fastjson.JSONObject;
import com.better.backend.mqReceiverService.examReceiver.model.ExamModel;
import com.better.backend.mqReceiverService.examReceiver.repository.ExamRepsitory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xiaq
 * 消息接收
 * @create 2017-09-23 12:01
 **/
@Component
public class ExamReceiver {
    @Autowired
    private ExamRepsitory examRepsitory;
    private static Log log = LogFactory.getLog(ExamReceiver.class);
    @RabbitListener(queues = "zxy_addExam")
    public void process(Message examModel) {
        String a = new String(examModel.getBody());
        log.info("接收添加考试消息：topic==zxy_addExam。"+a);
        ExamModel exam = JSONObject.parseObject(a, ExamModel.class);
        examRepsitory.save(exam);
    }
}
